package com.thresh;

import com.thresh.service.DemoService;
import org.apache.dubbo.rpc.RpcContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.Future;

/**
 * @Author YWB
 * @Date 2021/4/23
 * desc
 **/
public class ConsumerMain {
    public static void main(String[] args) throws Exception{
        ClassPathXmlApplicationContext context=new ClassPathXmlApplicationContext("classpath:/dubbo-consumer.xml");
        DemoService demoservice = context.getBean("demoService", DemoService.class);
        while (true){
            System.in.read();
            new ConcurrentHashMap<>();
            String thresh = demoservice.sayHello("thresh",1000);
            //使用future实现异步调用，xml配置中需要添加异步配置 async="true"
            Future<Object> future= RpcContext.getContext().getFuture();
            System.out.println(thresh);
            System.out.println("异步调用future result:"+future.get());
        }
    }
}
